package com.hospital.register.model.core;

import com.alibaba.fastjson.JSONArray;
import com.hospital.register.validation.groups.InsertValidation;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * RegisterRule
 * </p>
 *
 * @author qy
 */
@Data
@ApiModel(description = "预约规则")
@Document("BookingRule")
public class BookingRule {

    @ApiModelProperty(value = "预约周期")
    @NotNull(message = "预约周期不可为空", groups = InsertValidation.class)
    @Min(value = 0L, message = "预约周期不可<0", groups = InsertValidation.class)
    private Byte cycle;

    @ApiModelProperty(value = "放号时间")
    @NotBlank(message = "放号时间不可为空", groups = InsertValidation.class)
    private String releaseTime;

    @ApiModelProperty(value = "停挂时间")
    @NotBlank(message = "停挂时间不可为空", groups = InsertValidation.class)
    private String stopTime;

    @ApiModelProperty(value = "退号截止天数（如：就诊前一天为-1，当天为0）")
    @NotNull(message = "退号截止天数不可为空", groups = InsertValidation.class)
    @Min(value = 1, message = "退号截止天数不可<1", groups = InsertValidation.class)
    private Byte quitDay;

    @ApiModelProperty(value = "退号时间")
    @NotBlank(message = "退号时间不可为空", groups = InsertValidation.class)
    private String quitTime;

    @ApiModelProperty(value = "预约规则")
    @NotEmpty(message = "预约规则不可为空", groups = InsertValidation.class)
    private List<String> rule;

    /**
     * @param rule
     */
    public void setRule(String rule) {
        if (!StringUtils.isEmpty(rule)) {
            this.rule = JSONArray.parseArray(rule, String.class);
        }
    }

}

